﻿#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QWindow>
#include <QQmlContext>
#include <QQmlEngine>

#include "component/FpsItem.h"
#include "helper/log.h"
#include "test/windownative.h"
#include "component/filframeless.h"
#include "helper/filtools.h"
#include "test/mouseact.h"
#include "testapp.h"

int __test_main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    const char *uri = "SecAssistPro";
    int major = 1;
    int minor = 0;

    Log::setup(argv, uri);

    app.setOrganizationName("TimeChicken");
    app.setOrganizationDomain("timechicken.cc");
    app.setApplicationName("SecAssistPro");

    // @uri SecAssistPro
    qmlRegisterType<FpsItem>(uri, major, minor, "FpsItem");
    qmlRegisterType<FilFrameless>(uri, major, minor, "FilFrameless");
    qmlRegisterType<WindowsNative>(uri, major, minor, "WindowsNative");
    qmlRegisterSingletonType<FilTools>(uri, major, minor, "FilTools",
                                       [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
                                           Q_UNUSED(scriptEngine)
                                           QObject *instance = FilTools::getInstance();
                                           engine->setObjectOwnership(instance, QQmlEngine::CppOwnership);
                                           return instance;
                                       });

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("MouseAct", MouseAct::getInstance());
    // const QUrl url(QStringLiteral("qrc:/qml/main.qml"));
    // const QUrl url(QStringLiteral("qrc:/qml/window/MainWindow.qml"));
    // const QUrl url(QStringLiteral("qrc:/qml/test/TestWindow.qml"));
    // const QUrl url(QStringLiteral("qrc:/qml/test/FramelessWindow.qml"));
    // const QUrl url(QStringLiteral("qrc:/qml/test/TestAWindow.qml"));
    const QUrl url(QStringLiteral("qrc:/qml/test/TestAWindow.qml"));
    QObject::connect(
        &engine,
        &QQmlApplicationEngine::objectCreated,
        &app,
        [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        },
        Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
